package javagprssrv.StructClass;

import javagprssrv.Log;
import javagprssrv.JGS_Param;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class structTCPServerSocket
{
    public java.lang.String RemoteIP;
    public int RemotePort;
    public int LocalPort;
    public java.nio.channels.SocketChannel ServerChannel;
    public int TermKind;
    
    public void SendData(final java.lang.String _Data) {
        final int datasize = _Data.length();
        java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(datasize);
        try {
            final byte[] buf = new byte[_Data.length()];
            for (int i = 0; i < _Data.length(); ++i) {
                if (_Data.charAt(i) >= '\u0080') {
                    buffer.put(i, buf[i] = (byte)(_Data.charAt(i) - 'Ā'));
                }
                else {
                    buf[i] = (byte)_Data.charAt(i);
                }
            }
            buffer = java.nio.ByteBuffer.wrap(buf);
            this.ServerChannel.write(buffer);
            java.lang.String s = "[P=TCP,T=SEND " + java.lang.Integer.toString(_Data.length()) + ",LocalPort=" + java.lang.String.valueOf(this.LocalPort) + ",D=";
            s = s + this.RemoteIP + ":";
            s = s + java.lang.Integer.valueOf(this.RemotePort).toString().trim() + "] ";
            javagprssrv.JGS_Param.myLog.ShowLog(s + new javagprssrv.Log().String2HexString(_Data, " "), true, true);
            buffer = null;
        }
        catch (java.lang.Exception e) {
            java.lang.String s = "[P=TCP,T=SEND " + java.lang.Integer.toString(_Data.length()) + ",LocalPort=" + java.lang.String.valueOf(this.LocalPort) + ",D=";
            s = s + this.RemoteIP + ":";
            s = s + java.lang.Integer.valueOf(this.RemotePort).toString().trim() + "( 发送失败 )] ";
            javagprssrv.JGS_Param.myLog.ShowLog(s + new javagprssrv.Log().String2HexString(_Data, " "), true, true);
        }
    }
    
    public void SendData2(final java.lang.String _Data) {
        final int datasize = _Data.length();
        java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(datasize);
        buffer = java.nio.ByteBuffer.wrap(_Data.getBytes());
        for (int i = 0; i < _Data.length(); ++i) {
            java.lang.System.out.println("S[" + java.lang.String.valueOf(i) + "/" + java.lang.String.valueOf(_Data.length()) + "]=" + java.lang.Integer.toHexString(_Data.charAt(i)));
        }
        try {
            final byte[] buf = new byte[_Data.length()];
            for (int j = 0; j < _Data.length(); ++j) {
                if (_Data.charAt(j) >= '\u0080') {
                    buffer.put(j, buf[j] = (byte)(_Data.charAt(j) - 'Ā'));
                }
                else {
                    buf[j] = (byte)_Data.charAt(j);
                }
            }
            this.ServerChannel.write(buffer);
            java.lang.String s = "[P=TCP,T=SEND " + java.lang.Integer.toString(_Data.length()) + ",LocalPort=" + java.lang.String.valueOf(this.LocalPort) + ",D=";
            s = s + this.RemoteIP + ":";
            s = s + java.lang.Integer.valueOf(this.RemotePort).toString().trim() + "] ";
            javagprssrv.JGS_Param.myLog.ShowLog(s + new javagprssrv.Log().String2HexString(_Data, " "), true, true);
            buffer = null;
        }
        catch (java.lang.Exception e) {
            java.lang.String s = "[P=TCP,T=SEND " + java.lang.Integer.toString(_Data.length()) + ",LocalPort=" + java.lang.String.valueOf(this.LocalPort) + ",D=";
            s = s + this.RemoteIP + ":";
            s = s + java.lang.Integer.valueOf(this.RemotePort).toString().trim() + "( 发送失败 )] ";
            javagprssrv.JGS_Param.myLog.ShowLog(s + new javagprssrv.Log().String2HexString(_Data, " "), true, true);
        }
    }
}
